home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / pde_adi.pro < prev    next >
Text File  |  1997-07-08  |  7KB  |  250 lines

  1. ; $Id: pde_adi.pro,v 1.3 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ;  Copyright (c) 1992-1997, Research Systems Inc.  All rights
  4. ;  reserved. Unauthorized reproduction prohibited.
  5.  
  6. function BOUNDARY_LT,y,t
  7. ; left boundary condition as a function of y and t
  8.   bound=75.0
  9.   return,bound
  10. end
  11.  
  12. function BOUNDARY_RT,y,t
  13. ; right boundary condition as a function of y and t
  14.   bound=50.0
  15.   return,bound
  16. end
  17.  
  18. function BOUNDARY_BOT,x,t
  19. ; bottom boundary condition as a function of x and t
  20.   bound=0.0
  21.   return,bound
  22. end
  23.  
  24. function BOUNDARY_TOP,x,t
  25. ; top bondary condition as a function of x and t
  26.   bound=100.0
  27.   return,bound
  28. end
  29.  
  30. function NONHOMOGENEOUS,x,y,t
  31. ; the right hand side of the differential equation
  32. ; as a function of x, y, and t
  33.   nonhomo=0.0
  34.   return,nonhomo
  35. end
  36.  
  37. function INITIAL_COND,x,y
  38. ; the initial condition as a function of x and y
  39.   initial=0.0
  40.   return,initial
  41. end
  42.  
  43.  
  44. PRO PDE_ADI 
  45. ;+        
  46. ; NAME:
  47. ;    PDE_ADI
  48. ;
  49. ; PURPOSE:
  50. ;    This procedure computes the numerical solution of the 
  51. ;    initial-boundary value problem (parabolic partial  
  52. ;       differential equation) using the ADI method
  53. ;       (ALTERNATING DIRECTION IMPLICIT) in two space dimensions (x,y).
  54. ;      
  55. ; CATEGORY:
  56. ;    Numerical Analysis
  57. ;    
  58. ; CALLING SEQUENCE:
  59. ;    .run PDE_ADI     (compiles the procedure)
  60. ;    PDE_ADI        (runs the procedure)
  61. ;
  62. ; INPUTS:
  63. ;    There are no input parameters that can be specified from
  64. ;    the IDL command line. However, the following Internal
  65. ;    Parameters should be specified by editing the PDE_ADI.PRO
  66. ;    file before compiling the procedure:
  67. ;
  68. ;       DIFFUSIVITY ......................... DIFF
  69. ;       ENDPOINTS ........................... XMAX, YMAX
  70. ;       TIME STEP ........................... DELTA_TIME
  71. ;       NUMBER OF INTERIOR X-NODES .......... X_NODE_MAX
  72. ;       NUMBER OF INTERIOR Y-NODES .......... Y_NODE_MAX
  73. ;       NUMBER OF TIME STEPS ................ TIME_MAX
  74. ;
  75. ; OUTPUTS:
  76. ;    The numerical solution computed at each time step is stored
  77. ;    in the file PDE_ADI.DAT.
  78. ; RESTRICTIONS:
  79. ;    All Internal Parameters must be positive scalars.
  80. ;
  81. ; PROCEDURE:
  82. ;    This procedure uses the ADI method to compute the  
  83. ;       temperature U at each node (M,N) in the rectangular  
  84. ;       grid defined by DELTA_X and DELTA_Y for each time 
  85. ;       step from time=0 to time=TIME_MAX with steps of 
  86. ;       DELTA_TIME.
  87. ;
  88. ; EXAMPLE:
  89. ;    This procedure solves the partial differential equation:
  90. ;       Ut-diff*(Uxx+Uyy)=NONHOMOGENEOUS(X,Y,T)
  91. ;       Subject to the initial and boundary conditions:
  92. ;       U(x,y,0)=INITIAL_COND(X,Y)
  93. ;       U(0,y,t)=BOUNDARY_LT(Y,T)   U(1,y,t)=BOUNDARY_RT(Y,T)
  94. ;       U(x,0,t)=BOUNDARY_BOT(X,T)  U(x,1,t)=BOUNDARY_TOP(X,T)
  95. ;       where:
  96. ;             Ut ....   first partial derivative of U with respect to t
  97. ;             Uxx ...  second partial derivative of U with respect to x
  98. ;          Uyy ...  second partial derivative of U with respect to y
  99. ;
  100. ;       The computational grid has X_NODE_MAX x Y_NODE_MAX interior mesh points
  101. ;       and X_NODE_MAX+2 x Y_NODE_MAX+2 total mesh points. 
  102. ;
  103. ; MODIFICATION HISTORY:
  104. ;    GGS; AUGUST 1992
  105. ;    Adapted from:
  106. ;        Graduate course work at the University of Colorado, Boulder
  107. ;    Published References:
  108. ;        Advanced Engineering Mathematics (sixth edition)
  109. ;        Erwin Kreyzig
  110. ;        Wiley & Sons Inc.
  111. ;
  112. ;-
  113.  
  114. ON_ERROR,2
  115.  
  116. ; start timer
  117. TIME_0=SYSTIME(1)
  118.  
  119. ; define internal parameters
  120. DIFF=1.0
  121. DELTA_TIME=.01
  122. XMAX=1.0
  123. YMAX=1.0
  124. X_NODE_MAX=8
  125. Y_NODE_MAX=8
  126. TIME_MAX=50
  127.  
  128. ; allocate arrays
  129. X=FLTARR(X_NODE_MAX+2)
  130. Y=FLTARR(Y_NODE_MAX+2)
  131. U=FLTARR(X_NODE_MAX+2,Y_NODE_MAX+2)
  132. V=FLTARR(X_NODE_MAX+2,Y_NODE_MAX+2)
  133. DIMENSION=max([X_NODE_MAX,Y_NODE_MAX])+1
  134. A=FLTARR(DIMENSION)
  135. B=FLTARR(DIMENSION)
  136. C=FLTARR(DIMENSION)
  137. D=FLTARR(DIMENSION)
  138.  
  139. ; define computational grid
  140. DELTA_X=XMAX/FLOAT(X_NODE_MAX+1)
  141. DELTA_Y=YMAX/FLOAT(Y_NODE_MAX+1)
  142.  
  143. ; define computational ratios
  144. X_RATIO=DIFF*DELTA_TIME/(DELTA_X^2.0)
  145. Y_RATIO=DIFF*DELTA_TIME/(DELTA_Y^2.0)
  146.  
  147. T=0.0
  148.  
  149. ; realize computational grid
  150. FOR M=1,X_NODE_MAX DO $
  151.   X(M)=X(M-1)+DELTA_X
  152. FOR N=1,Y_NODE_MAX DO $
  153.   Y(N)=Y(N-1)+DELTA_Y
  154. X(X_NODE_MAX+1)=XMAX
  155. Y(Y_NODE_MAX+1)=YMAX
  156.  
  157. ; initialize corners of computational grid 
  158. U(0,0)=0.5*(BOUNDARY_LT(Y(0),T)+BOUNDARY_BOT(X(0),T))
  159. U(0,Y_NODE_MAX+1)=0.5*(BOUNDARY_LT(Y(0),T)+BOUNDARY_TOP(X(0),T))
  160. U(X_NODE_MAX+1,Y_NODE_MAX+1)=0.5*(BOUNDARY_TOP(X(0),T)+BOUNDARY_RT(Y(0),T))
  161. U(X_NODE_MAX+1,0)=0.5*(BOUNDARY_RT(Y(0),T)+BOUNDARY_BOT(X(0),T))
  162.  
  163. ; compute initial values of U(M,N) on the interior of grid
  164. ; this is the temperature of the interior grid at TIME= zero
  165. FOR N=1,Y_NODE_MAX DO BEGIN
  166.   FOR M=1,X_NODE_MAX DO $
  167.     U(M,N)=INITIAL_COND(X(M),Y(N))
  168. ENDFOR
  169.  
  170. ;open data file: PDE_ADI.DAT
  171. OPENW,22,'PDE_ADI.DAT'
  172.  
  173. ; output solution at T=0.0
  174. PRINTF,22,FORMAT='(/"  Time = ",F5.2,/)',T
  175. PRINTF,22,'  NUMERICAL SOLUTION'
  176. FOR N=Y_NODE_MAX+1,0,-1 DO $
  177.   PRINTF,22,FORMAT='(20(F7.2,1x))',U(0:X_NODE_MAX+1,N)
  178.  
  179. ; start time steps
  180. FOR J=1,TIME_MAX DO BEGIN
  181.  
  182. ; start y-direction computation
  183.   FOR N=1,Y_NODE_MAX DO BEGIN
  184.     FOR M=1,X_NODE_MAX DO BEGIN
  185.       A(M)=-X_RATIO/2.0
  186.       B(M)=1.0+X_RATIO
  187.       C(M)=-X_RATIO/2.0
  188.       D(M)=0.5*Y_RATIO*U(M,N-1)+(1.0-Y_RATIO)*U(M,N)+0.5*Y_RATIO*U(M,N+1)
  189.       D(M)=D(M)+0.5*DELTA_TIME*(NONHOMOGENEOUS(X(M),Y(N),T) $
  190.                +NONHOMOGENEOUS(X(M),Y(N),T+DELTA_TIME))
  191.     ENDFOR  
  192.     U(0,N)=BOUNDARY_LT(Y(N),T+DELTA_TIME)
  193.     V(0,N)=0.25*Y_RATIO*(BOUNDARY_LT(Y(N-1),T)+BOUNDARY_LT(Y(N+1),T)) $
  194.                +(0.5-0.25*Y_RATIO)*BOUNDARY_LT(Y(N),T) $
  195.                -0.25*Y_RATIO*(BOUNDARY_LT(Y(N-1),T+DELTA_TIME) $
  196.                +BOUNDARY_LT(Y(N+1),T+DELTA_TIME)) $
  197.                +(0.5+0.25*Y_RATIO)*BOUNDARY_LT(Y(N),T+DELTA_TIME)
  198.     D(1)=D(1)+0.5*X_RATIO*V(0,N)
  199.     U(X_NODE_MAX+1,N)=BOUNDARY_RT(Y(N),T+DELTA_TIME)
  200.     V(X_NODE_MAX+1,N)=0.25*Y_RATIO*(BOUNDARY_RT(Y(N-1),T)+BOUNDARY_RT(Y(N+1),T)) $
  201.                           +(0.5-0.25*Y_RATIO)*BOUNDARY_RT(Y(N),T) $
  202.                           -0.25*Y_RATIO*(BOUNDARY_RT(Y(N-1),T+DELTA_TIME) $
  203.                           +BOUNDARY_RT(Y(N+1),T+DELTA_TIME)) $
  204.                           +(0.5+0.25*Y_RATIO)*BOUNDARY_RT(Y(N),T+DELTA_TIME)
  205.     D(X_NODE_MAX)=D(X_NODE_MAX)+0.5*X_RATIO*V(X_NODE_MAX+1,N)
  206.     TRIDAG,A(1:X_NODE_MAX),B(1:X_NODE_MAX),C(1:X_NODE_MAX),D(1:X_NODE_MAX),WEIGHT
  207.     FOR M=1,X_NODE_MAX DO $
  208.       V(M,N)=WEIGHT(M-1)
  209.   ENDFOR
  210.  
  211. ; start x-direction computation
  212.   FOR M=1,X_NODE_MAX DO BEGIN
  213.     FOR N=1,Y_NODE_MAX DO BEGIN
  214.       A(N)=-Y_RATIO/2.0
  215.       B(N)=1.0+Y_RATIO
  216.       C(N)=-Y_RATIO/2.0
  217.       D(N)=0.5*X_RATIO*V(M-1,N)+(1.0-X_RATIO)*V(M,N)+0.5*X_RATIO*V(M+1,N)
  218.       D(N)=D(N)+0.5*DELTA_TIME*(NONHOMOGENEOUS(X(M),Y(N),T) $
  219.                +NONHOMOGENEOUS(X(M),Y(N),T+DELTA_TIME))
  220.     ENDFOR
  221.     U(M,0)=BOUNDARY_BOT(X(M),T+DELTA_TIME)
  222.     D(1)=D(1)+0.5*Y_RATIO*U(M,0)
  223.     U(M,Y_NODE_MAX+1)=BOUNDARY_TOP(X(M),T+DELTA_TIME)
  224.     D(Y_NODE_MAX)=D(Y_NODE_MAX)+0.5*Y_RATIO*U(M,Y_NODE_MAX+1)
  225.     TRIDAG,A(1:Y_NODE_MAX),B(1:Y_NODE_MAX),C(1:Y_NODE_MAX),D(1:Y_NODE_MAX),WEIGHT
  226.     FOR N=1,Y_NODE_MAX DO $
  227.       U(M,N)=WEIGHT(N-1)
  228.   ENDFOR
  229.  
  230. ; let user know how the algorithm is progressing
  231.    PRINT,' ... time step complete     REAL TIME = ',T, ' seconds'
  232.  
  233. ; advance to next time step
  234.     T=T+DELTA_TIME
  235.  
  236. ; output solution at time step T
  237.     PRINTF,22,FORMAT='(/"  Time = ",F5.2,/)',T
  238.     PRINTF,22,'  NUMERICAL SOLUTION'
  239.     FOR N=Y_NODE_MAX+1,0,-1 DO $
  240.       PRINTF,22,FORMAT='(20(F7.2,1x))',U(0:X_NODE_MAX+1,N)
  241. ENDFOR    
  242.  
  243. ; close data file: PDE_ADI.DAT
  244. CLOSE,22
  245.  
  246. PRINT,'             program execution in ...',SYSTIME(1)-TIME_0,' seconds'
  247.  
  248. END
  249.